package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysAttendanceList;
import com.ruoyi.system.service.ISysAttendanceListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排班列Controller
 * 
 * @author ruoyi
 * @date 2023-01-31
 */
@RestController
@RequestMapping("/system/list")
public class SysAttendanceListController extends BaseController
{
    @Autowired
    private ISysAttendanceListService sysAttendanceListService;

    /**
     * 查询排班列列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAttendanceList sysAttendanceList)
    {
        startPage();
        List<SysAttendanceList> list = sysAttendanceListService.selectSysAttendanceListList(sysAttendanceList);
        return getDataTable(list);
    }

    /**
     * 导出排班列列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:export')")
    @Log(title = "排班列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysAttendanceList sysAttendanceList)
    {
        List<SysAttendanceList> list = sysAttendanceListService.selectSysAttendanceListList(sysAttendanceList);
        ExcelUtil<SysAttendanceList> util = new ExcelUtil<SysAttendanceList>(SysAttendanceList.class);
        return util.exportExcel(list, "list");
    }

    /**
     * 获取排班列详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:query')")
    @GetMapping(value = "/{listId}")
    public AjaxResult getInfo(@PathVariable("listId") Long listId)
    {
        return AjaxResult.success(sysAttendanceListService.selectSysAttendanceListById(listId));
    }

    /**
     * 新增排班列
     */
    @PreAuthorize("@ss.hasPermi('system:list:add')")
    @Log(title = "排班列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAttendanceList sysAttendanceList)
    {
        sysAttendanceList.setTime(new Date());
        return toAjax(sysAttendanceListService.insertSysAttendanceList(sysAttendanceList));
    }

    /**
     * 修改排班列
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "排班列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAttendanceList sysAttendanceList)
    {
        sysAttendanceList.setTime(new Date());
        return toAjax(sysAttendanceListService.updateSysAttendanceList(sysAttendanceList));
    }

    /**
     * 删除排班列
     */
    @PreAuthorize("@ss.hasPermi('system:list:remove')")
    @Log(title = "排班列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{listIds}")
    public AjaxResult remove(@PathVariable Long[] listIds)
    {
        return toAjax(sysAttendanceListService.deleteSysAttendanceListByIds(listIds));
    }
}
